package cn.bearspark.framework.web.starter.config;

import cn.bearspark.framework.web.starter.interceptor.RequestLimitInterceptor;
import cn.bearspark.framework.web.starter.interceptor.TokenParseInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 网络请求的拦截器的配置类
 *
 * @author f
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    private final TokenParseInterceptor tokenParseInterceptor;
    private final RequestLimitInterceptor requestLimitInterceptor;

    public WebConfig(TokenParseInterceptor tokenParseInterceptor,
                     RequestLimitInterceptor requestLimitInterceptor) {
        this.tokenParseInterceptor = tokenParseInterceptor;
        this.requestLimitInterceptor = requestLimitInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenParseInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/error");
        registry.addInterceptor(requestLimitInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/error");
    }
}
